package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类使用方法
 */
@Configuration
public class ConfigClass {

    /**
     * 声明queue队列名
     * @return
     */
    @Bean
    public Queue queue1() {
        return new Queue("simple.queue1");
    }
    @Bean
    public Queue queue2() {
        return new Queue("simple.queue2");
    }

    /**
     * 声明交换机名
     * 返回值FanoutExchange，DirectExchange，TopicExchange根据需要使用
     * @return
     */
    @Bean
    public FanoutExchange exchange() {
        return new FanoutExchange("exchange.fanout");
    }

    /**
     * 将队列和交换机进行绑定
     * @param simpleQueue1 队列名
     * @param exchangeFanout 交换机名
     * @return
     */
    @Bean
    public Binding binding1(Queue simpleQueue1,FanoutExchange exchangeFanout) {
        return BindingBuilder.bind(simpleQueue1).to(exchangeFanout);
    }

    @Bean
    public Binding binding2(Queue simpleQueue2,FanoutExchange exchangeFanout) {
        return BindingBuilder.bind(simpleQueue2).to(exchangeFanout);
    }



}
